

function addSensorbitCod(Blockly) {




   //RGB模块初始化
Blockly.Python.microbit_rgbcolorInit = function(block) {
    var dropdown_green = this.getFieldValue('green');
    var dropdown_blue = this.getFieldValue('blue');
    var dropdown_red = this.getFieldValue('red');
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
    Blockly.Python.definitions_['import_RGB'] = 'from monitor import led';
    Blockly.Python.definitions_['green'] = 'greenPort = '+dropdown_green+'';
    Blockly.Python.definitions_['blue'] = 'bluePort = '+dropdown_blue+'';
    Blockly.Python.definitions_['red'] = 'redPort = '+dropdown_red+'';
    return '';
  }
  
   //RGB灯模块
   Blockly.Python.microbit_rgbcolor = function(block) {
    // var dropdown_red = Blockly.Python.valueToCode(this, 'rgbr', Blockly.Python.ORDER_ATOMIC);
    // var dropdown_green = Blockly.Python.valueToCode(this, 'rgbg', Blockly.Python.ORDER_ATOMIC);
    // var dropdown_blue = Blockly.Python.valueToCode(this, 'rgbb', Blockly.Python.ORDER_ATOMIC);
    var dropdown_colour = block.childBlocks_[0].colour_;
    var colorStr = dropdown_colour.colorRgb();
    var red_color = 0;
    var blue_color = 0;
    var green_color = 0;
    if (colorStr) {
      var colorArr = colorStr.split(",");
      red_color = colorArr[0];
      green_color = colorArr[1];
      blue_color = colorArr[2];
   }
    var code = "led.brightness(greenPort, " + green_color + ")\nled.brightness(bluePort, " + blue_color + ")\nled.brightness(redPort, " + red_color + ")\n";
    return code;
  }
  

    return Blockly;
}

module.exports = addSensorbitCod;

